<?php
  //global $customer_id;
  require('includes/application_top.php');
  require('includes/classes/http_client.php');

  $breadcrumb->add('Trợ giúp', tep_href_link('helps.php', '', 'SSL'));   
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
    <title><?php echo TITLE; ?></title>
    <base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">         
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="3" cellpadding="3">
  <tr>
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
    </table></td>
<!-- body_text //-->
    <td width="100%" valign="top" align="left">   
    <table border="0" cellpadding="4" cellspacing="4" width="100%">
    <div class="home-newprodbar">
    <?php 
    $cat_query = tep_db_query("select title from content_category where id=".(int)$_GET['catid']);
            $cat = tep_db_fetch_array($cat_query);
    ?>
                    <div class="lblTitle">Tin tức - <?php echo $cat['title'] ?></div>
                </div><br /><br /><br /> 
        <!--<tr><td class="title_orders" colspan="2" style="padding-left: 15px;">Danh sách các trợ giúp</td></tr>-->
        <tr><td align="left">
        <?php
            $helps_query = tep_db_query("select count(id) as total from content where catid=".(int)$_GET['catid']);
            $helps_total = tep_db_fetch_array($helps_query);
            if ($helps_total > 0) {
                $helps_query_raw = "select * from content where catid=".(int)$_GET['catid']." order by created_date";
                $helps_split = new splitPageResults($helps_query_raw, MAX_DISPLAY_PAGE_LINKS);
                $helps_query = tep_db_query($helps_split->sql_query);
                $count = 0;
                while ($helps = tep_db_fetch_array($helps_query)) {
                    $count++;
                    
        ?>
                  <div class="wrp_listnews">
            <a href="news_detail.php?id=<?php echo (int)$helps['id']; ?>">
            <img width="130" alt="<?php echo $helps['title'] ?>" src="<?php echo catch_that_image($helps['content']) ?>" class="img_news_gray"></a>
            <a href="news_detail.php?id=<?php echo (int)$helps['id']; ?>">
            <p class="text_title_news_gray">
                <?php echo $helps['title'] ?>
            </p>
            </a>
            <p>
            <?php echo description($helps['content'],0,200); ?>
            </p>
            <div class="clearfix"></div>
        </div>
            <?php
                }
            }
            ?>
        </td></tr>        
        <?php
          if ($helps_total['total'] > 0) {
        ?>
                <tr><td>
                    <div class="pagecount">
                        <div class="pagenum"><?php //echo $helps_split->display_count(TEXT_DISPLAY_NUMBER_OF_ORDERS_PRODUCT); ?></div>
                        <ul class="pagelist">
                            <?php echo $helps_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?>
                        </ul>
                    </div>
                </td></tr>
        <?php
          }
        ?>     
    </table>
</td>
<!-- body_text_eof //-->
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<!-- right_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_right.php'); ?>
<!-- right_navigation_eof //-->
    </table></td>
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
<?php 
function catch_that_image($content) {
  $first_img = '';
  ob_start();
  ob_end_clean();
  $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $content, $matches);
  $first_img = $matches [1] [0];

  if(empty($first_img)){ //Defines a default image
    $first_img = "/images/default.jpg";
  }
  return $first_img;
}

function description($string,$start,$length){
        $string=strip_tags($string);
        if(strlen($string)>$length){
            return substr($string,$start,$length).'...';    
        }else{
            return substr($string,$start,$length);
        }
        
    }
?>